//
//  PS_FuTouViewController.m
//  FinanceSupermarket
//
//  Created by 丹丹 on 2018/12/13.
//  Copyright © 2018年 xuezi. All rights reserved.
//

#import "PS_FuTouViewController.h"
#import "PS_DummyStatusView.h"
#import "PS_WangDaiListTableViewCell.h"
#import "PS_WangDaiModel.h"
#import "PS_WangDaiFanLiDetailViewController.h"
@interface PS_FuTouViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    int pageNO;
    PS_DummyStatusView *dummyView;
}

@property (nonatomic, strong)UITableView * listTable;
@property(nonatomic, strong)NSMutableArray * dataArray;
@end

@implementation PS_FuTouViewController
- (NSMutableArray *)dataArray{
    
    if (_dataArray == nil) {
        
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (UITableView *)listTable{
    
    if (_listTable == nil) {
        
        _listTable = [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,SCREEN_HEIGHT - SafeAreaTopHeight -30 - SafeAreaBottomHeight)];
        _listTable.dataSource = self;
        _listTable.delegate = self;
        _listTable.showsVerticalScrollIndicator= NO;
        _listTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listTable.backgroundColor = RGBCOLOR(238, 238, 238);
    }
    
    return _listTable;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.nav_btmView.hidden = YES;
    self.view.backgroundColor = RGBCOLOR(238, 238, 238);
    [self.view addSubview:self.listTable];
    [self getWangDaiListData];
    // Do any additional setup after loading the view.
}
#pragma mark - delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 190;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    PS_WangDaiListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PS_WangDaiListTableViewCell"];
    if (cell == nil) {

        cell = [[[NSBundle mainBundle]loadNibNamed:@"PS_WangDaiListTableViewCell" owner:self options:nil]objectAtIndex:0];

    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    PS_WangDaiModel * model = [self.dataArray objectAtIndex:indexPath.row];
    cell.c_ftFanLiLabel.text = model.repeat_description;
    [cell.submitButton addTarget:self action:@selector(pushDetail:) forControlEvents:UIControlEventTouchUpInside];
    cell.submitButton.tag = indexPath.row;
    [cell setDataForCell:model];

    return cell;

}

- (void)pushDetail:(UIButton *)sender{
    
    NSInteger tag = sender.tag;
    
    PS_WangDaiModel * model = [self.dataArray objectAtIndex:tag];
    PS_WangDaiFanLiDetailViewController * VC = [[PS_WangDaiFanLiDetailViewController alloc]init];
    VC.merchant_id = model.wdID;
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)getWangDaiListData{
    
    [Utils post:MERCHANTLIST parameters:nil success:^(NSInteger recode, id jsonObject) {
        
        NSDictionary * dic = [jsonObject objectForKey:@"data"];
        NSArray *normal_typeArr = [dic objectForKey:@"normal_type"];
        NSArray *repeat_typeArr = [dic objectForKey:@"repeat_type"];
        if (repeat_typeArr.count >0) {
            
            for (NSDictionary * dict in repeat_typeArr) {
                
                NSString * idStr = [dict objectForKey:@"id"];
                PS_WangDaiModel * model = [PS_WangDaiModel mj_objectWithKeyValues:dict];
                model.wdID = idStr;
                [self.dataArray addObject:model];
            }
        }
        
        [self.listTable reloadData];
        
    } failure:^(NSInteger recode, NSError *error) {
        
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
